package com.wlh.demo03;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ThreadPoolDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建线程池对象
        //包含两个线程对象
        ExecutorService service = Executors.newFixedThreadPool(2);
        //创建Callable接口子类对象
        MyCallable c = new MyCallable(100, 200);
        MyCallable c2 = new MyCallable(10, 20);
        //Future结果对象
        Future<Integer> result = service.submit(c);
        Integer sum = result.get();
        System.out.println("sum = " + sum);
        //再次演示
        Future<Integer> result2 = service.submit(c2);
        Integer sum2 = result2.get();
        System.out.println("sum2 = " + sum2);

        service.shutdown();
    }
}
